package com.example.springtest.file.controller;

import com.example.springtest.common.R;
import com.example.springtest.file.pojo.File;
import com.example.springtest.file.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("file")
@Api(tags = "文件模块")
public class FileController {

    @Autowired
    private FileService fileService;

    @PostMapping("/upload")
    @ApiOperation("上传文件")
    public R<Void> uploadFile(@RequestParam("file") MultipartFile file,
                              @RequestParam(value = "name", required = false) String name,
                              @RequestParam(value = "owner", required = false) String owner) {
        fileService.uploadFile(file, name, owner);
        return R.ok();
    }

    @GetMapping("/view")
    @ApiOperation("查看文件")
   public R<List<File>> getFileList(){
        List<File> fileList=fileService.getFileList();
        return R.ok(fileList);
    }
}